<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>插入超链接</title>
<style type="text/css">
<!--
*{padding: 0px; margin: 0px;}
html, body {font-size: 12px; text-align: left; line-height: 18px; padding: 0px; margin:0px; background: #edeae7; overflow: hidden;}
ol,ul,li{list-style:none; margin: 0px; padding: 0px; }
h1,h2,h3,h4,h5,font{ font-size: 12px;}

a:link    {font-size: 12px; color: #000000; text-decoration: none; border:none;}
a:visited {font-size: 12px; color: #000000; text-decoration: none; border:none;}
a:hover   {font-size: 12px; color: #ec7e2d; text-decoration: underline; border:none;}
a:active  {font-size: 12px; color: #000000; text-decoration: none; border:none;}

a img{ border: none;}
.mclear{clear: both; visibility: hidden; font-size: 0px; line-height: 0px; padding: 0px; margin: 0px;}

#Panel{text-align: left; padding-left: 15px; padding-top: 6px;}
	#Panel li{ padding-top: 7px;}
	#Panel select{ font-size: 12px;}
	#Panel .inputs{ font-size: 12px;}
	#Panel .xBtn{ border: 1px solid #333;}
-->
</style>
<script type="text/javascript" src="dialog.js"></script>
<script type="text/javascript">
var sAction = URLParams["action"];
var sUrl,sTarget,sProtocol;

switch (sAction){
case "Other":
	sUrl = oCtrlWin.document.objLink.Href;
	sTarget = oCtrlWin.document.objLink.Target;
	sProtocol = getProtocol(sUrl);
	break;
default:
	var oRange = oMyEditor.seleRestore();
	var oNode;
	try{
		if(isIE){
			if(typeof(oRange.parentNode)=="object"){
				oNode = oRange.parentNode;
			}else{
				oNode = oRange.parentElement();
			}
			if (oNode.tagName.toLowerCase() == "a"){
				sTarget = oNode.getAttribute("target", 2);
				sUrl = oNode.getAttribute("href", 2);
				sProtocol = getProtocol(sUrl);
			}
		}else{
			if(oRange.startContainer != oRange.endContainer){
				oNode=oRange.endContainer;
				if(oNode.parentNode.nodeName.toLowerCase() == "a"){
					sTarget = oNode.parentNode.getAttribute("target", 2);
					sUrl = oNode.parentNode.getAttribute("href", 2);
					sProtocol = getProtocol(sUrl);
				}
			}
		}
	}catch(e){
	
	}
	break;
}

function getProtocol(url){
	var re=/(.+:\/*)(.*)/gi;
	return url.replace(re,"$1");
}

window.onload=InitDocument;

function InitDocument(){
	
	if(typeof(sProtocol)!="undefined"){
		SearchSelectValue($("d_protocol"), sProtocol.toLowerCase());
	}
	if(typeof(sTarget)!="undefined"){
		SearchSelectValue($("d_target"), sTarget.toLowerCase());
	}
	if(typeof(sUrl)!="undefined"){
		$("d_url").value = sUrl;
	}
}

function changeProtocol(index){
	sProtocol=$("d_protocol").options[index].value;
	sUrl = $("d_url").value;
	if(sUrl.indexOf("tencent://")!=-1){
		sUrl="";
	}
	var re = /(.+:\/*)/gi;
	sUrl = sUrl.replace(re, "");
	$("d_url").value = sProtocol + sUrl;
}
function SubThis(){
	sUrl = $("d_url").value;
	sTarget = $("d_target").options[$("d_target").selectedIndex].value;
	if (sUrl != ""){
		switch (sAction){
		case "Other":
			var arr = new Array();
			arr[0] = sUrl;
			arr[1] = sTarget;
			break;
		default:
			var oRange = oMyEditor.seleRestore();
			var sTurl = "iel_editor_links";
			oCtrlWin.document.execCommand('CreateLink',false,sTurl);
			var alinks = oCtrlWin.document.links;
			for(var i = 0 ; i < alinks.length ; i++){
				olink = alinks[i] ;
				if(olink.getAttribute("href", 2) == sTurl){
					olink.setAttribute("href", sUrl);
					if(sTarget!=""){
						olink.setAttribute("target", sTarget);
					}
				}
			}
			break;
		}
	}else{
		alert("链接地址不能为空");
		$("d_url").focus();
		return;
	}
	xClose();
}
</script>
</head>
<body>
<div id="Panel">
    <ul>
        <li>
            <select id="d_protocol" onchange="changeProtocol(this.selectedIndex)">
                <option value="http://" selected="selected">http:</option>
                <option value="https://">https:</option>
                <option value="tencent://message/?uin=">QQ:</option>
                <option value="ftp://">ftp:</option>
                <option value="mailto:">mailto:</option>
            </select>&nbsp;
            <select id="d_target">
                <option value="">默认(无)</option>
                <option value="_self">当前窗口</option>
                <option value="_blank">新建窗口</option>
            </select>
        </li>
        <li>
            <input class="inputs" name="d_url" type="text" id="d_url" value="http://" size="35" maxlength="200" />
        </li>
        <li>
            <input class="xBtn" type="button" name="SubBtn" id="SubBtn" onclick="SubThis();" value="确定" />
            <input class="xBtn" type="button" name="NoBtn" id="NoBtn" onclick="xClose();" value="取消" />
      	</li>
    </ul>
</div>
</body>
</html>
